<?php

namespace App\Models;

class Admin extends Base
{
    const STATUS_BEGIN       = 1;//启用
    const STATUS_STOP        = 2;//申请审核

    protected $table = 'wd_system_admin';


    /**
     * 获取关联到部门表的数据
     */
/*    public function department()
    {
        return $this->hasOne('App\Department', 'department_id');
    }*/

    public function adminList($params, $page) {

        $builderObj = $this->getQuery($params);
 
        $builderObj = $this->where('status', Admin::STATUS_BEGIN)->get();

        
        //$result = $this->where('status', Admin::STATUS_BEGIN)->paginate($page)->toArray();
 
        dd($data);
        $this->data = $result;
    }
    
    /**
     * 获得sql
     * @param  array  $params [请求参数]
     * @return [type]         [this]
     */
    public function getQuery(array $params) {

        $builderObj = $this;

        if (!empty($params)) {
            
            extract($params);

            if ($name != null) {
                $builderObj = $builderObj->where('name', 'like', '%'.$name.'%');
            }
            if ($department != 0) {
                $builderObj = $builderObj->where('department', $department);
            }
            if ($level != 0) {
                $builderObj = $builderObj->where('level', $level);
            }
        }

        return $builderObj;
    }
}
